if ((path == NULL) || (buf == NULL))
return 0;
- ret = xs_write(h, path, buf, strlen(buf)+1, O_CREAT);
+ ret = xs_write(h, path, buf, strlen(buf)+1);
free(buf);
free(path);
success = asprintf(&path, "%s/tty", dom->conspath) != -1;
if (!success)
goto out;
- success = xs_write(xs, path, slave, strlen(slave), O_CREAT);
+ success = xs_write(xs, path, slave, strlen(slave));
free(path);
if (!success)
goto out;
"Write data to a path.\n" \
" path [string] : xenstore path to write to\n." \
" data [string] : data to write.\n" \
- " create [int] : create flag, default 0.\n" \
- " excl [int] : exclusive flag, default 0.\n" \
"\n" \
"Returns None on success.\n" \
"Raises RuntimeError on error.\n" \
static PyObject *xspy_write(PyObject *self, PyObject *args, PyObject *kwds)
{
- static char *kwd_spec[] = { "path", "data", "create", "excl", NULL };
- static char *arg_spec = "ss#|ii";
+ static char *kwd_spec[] = { "path", "data", NULL };
+ static char *arg_spec = "ss#";
char *path = NULL;
char *data = NULL;
int data_n = 0;
- int create = 0;
- int excl = 0;
struct xs_handle *xh = xshandle(self);
PyObject *val = NULL;
- int flags = 0;
int xsval = 0;
if (!xh)
goto exit;
if (!PyArg_ParseTupleAndKeywords(args, kwds, arg_spec, kwd_spec,
- &path, &data, &data_n, &create, &excl))
+ &path, &data, &data_n))
goto exit;
- if (create)
- flags |= O_CREAT;
- if (excl)
- flags |= O_EXCL;
Py_BEGIN_ALLOW_THREADS
- xsval = xs_write(xh, path, data, data_n, flags);
+ xsval = xs_write(xh, path, data, data_n);
Py_END_ALLOW_THREADS
if (!xsval) {
PyErr_SetFromErrno(PyExc_RuntimeError);
if x == "": continue
p = os.path.join(p, x)
if not self.exists(p):
- self.getxs().write(p, "", create=True)
+ self.getxs().write(p, "")
def read(self, path):
try:
else:
raise
- def create(self, path, excl=False):
- self.write(path, "", create=True, excl=excl)
+ def create(self, path):
+ self.write(path, "")
- def write(self, path, data, create=True, excl=False):
- self.mkdirs(path)
+ def write(self, path, data):
try:
- self.getxs().write(path, data, create=create, excl=excl)
+ self.getxs().write(path, data)
except Exception, ex:
raise
ret.append(self._read(key))
return ret
- def _write(self, key, data, create=True, excl=False):
+ def _write(self, key, data):
path = "%s/%s" % (self.path, key)
- xshandle().write(path, data, create=create, excl=excl)
+ xshandle().write(path, data)
def write(self, *args, **opts):
- create = opts.get('create') or True
- excl = opts.get('excl') or False
if len(args) == 0:
raise TypeError
if isinstance(args[0], dict):
raise TypeError
for key in d.keys():
try:
- self._write(key, d[key], create, excl)
+ self._write(key, d[key])
except TypeError, msg:
raise TypeError('Writing %s: %s: %s' %
(key, str(d[key]), msg))
-
elif isinstance(args[0], list):
for l in args:
if not len(l) == 2:
raise TypeError
- self._write(l[0], l[1], create, excl)
+ self._write(l[0], l[1])
elif len(args) % 2 == 0:
for i in range(len(args) / 2):
- self._write(args[i * 2], args[i * 2 + 1], create, excl)
+ self._write(args[i * 2], args[i * 2 + 1])
else:
raise TypeError
# Create an entry, read it.
-write /test create contents
+write /test contents
expect contents
read /test
dir /
# Create a file.
-write /test create contents
+write /test contents
# Directory shows it.
expect test
dir /dir
# Create a file, check it exists.
-write /dir/test2 create contents2
+write /dir/test2 contents2
expect test2
dir /dir
expect contents2
-# Write without create fails.
-expect write failed: No such file or directory
-write /test none contents
-
-# Exclusive write succeeds
-write /test excl contents
+# Write succeeds
+write /test contents
expect contents
read /test
-# Exclusive write fails to overwrite.
-expect write failed: File exists
-write /test excl contents
-
-# Non-exclusive overwrite succeeds.
-write /test none contents2
+# Overwrite succeeds.
+write /test contents2
expect contents2
read /test
-write /test create contents3
-expect contents3
-read /test
# Write should implicitly create directories
-write /dir/test create contents
+write /dir/test contents
expect test
dir /dir
expect contents
read /dir/test
-write /dir/1/2/3/4 excl contents4
+write /dir/1/2/3/4 contents4
expect test
expect 1
dir /dir
rm /dir/test
# Create file and remove it
-write /test excl contents
+write /test contents
rm /test
# Create directory and remove it.
# Create directory, create file, remove all.
mkdir /dir
-write /dir/test excl contents
+write /dir/test contents
rm /dir
getperm /dir/test
# Create file: inherits from root (0 READ)
-write /test excl contents
+write /test contents
expect 0 READ
getperm /test
setid 1
expect contents
read /test
expect write failed: Permission denied
-write /test none contents
+write /test contents
# Take away read access to file.
setid 0
expect read failed: Permission denied
read /test
expect write failed: Permission denied
-write /test none contents
+write /test contents
# Grant everyone write access to file.
setid 0
getperm /test
expect read failed: Permission denied
read /test
-write /test none contents2
+write /test contents2
setid 0
expect contents2
read /test
getperm /test
expect contents2
read /test
-write /test none contents3
+write /test contents3
expect contents3
read /test
getperm /test
expect contents3
read /test
-write /test none contents4
+write /test contents4
# User 2 can do nothing.
setid 2
expect read failed: Permission denied
read /test
expect write failed: Permission denied
-write /test none contents4
+write /test contents4
# Tools can always access things.
setid 0
getperm /test
expect contents4
read /test
-write /test none contents5
+write /test contents5
getperm /dir
dir /dir
expect write failed: Permission denied
-write /dir/test create contents2
+write /dir/test contents2
# Remove everyone's read access to directoy.
setid 0
expect read failed: Permission denied
read /dir/test create contents2
expect write failed: Permission denied
-write /dir/test create contents2
+write /dir/test contents2
# Grant everyone write access to directory.
setid 0
getperm /dir
expect dir failed: Permission denied
dir /dir
-write /dir/test create contents
+write /dir/test contents
setid 0
expect 1 WRITE
getperm /dir/test
getperm /dir
expect test
dir /dir
-write /dir/test2 create contents
+write /dir/test2 contents
expect contents
read /dir/test2
setperm /dir/test2 1 NONE
expect test
expect test2
dir /dir
-write /dir/test3 create contents
+write /dir/test3 contents
# User 2 can do nothing. Can't even tell if file exists.
setid 2
expect read failed: Permission denied
read /dir/test4
expect write failed: Permission denied
-write /dir/test none contents
+write /dir/test contents
expect write failed: Permission denied
-write /dir/test create contents
-expect write failed: Permission denied
-write /dir/test excl contents
-expect write failed: Permission denied
-write /dir/test4 none contents
-expect write failed: Permission denied
-write /dir/test4 create contents
-expect write failed: Permission denied
-write /dir/test4 excl contents
+write /dir/test4 contents
# Tools can always access things.
setid 0
expect test2
expect test3
dir /dir
-write /dir/test4 create contents
+write /dir/test4 contents
# Inherited by child.
mkdir /dir/subdir
expect 1 NONE
getperm /dir/subdir
-write /dir/subfile excl contents
+write /dir/subfile contents
expect 1 NONE
getperm /dir/subfile
expect 2 READ/WRITE
getperm /dir/subdir
setid 3
-write /dir/subdir/subfile excl contents
+write /dir/subdir/subfile contents
expect 3 READ/WRITE
getperm /dir/subdir/subfile
# Inheritence works through multiple directories, too.
-write /dir/subdir/1/2/3/4 excl contents
+write /dir/subdir/1/2/3/4 contents
expect 3 READ/WRITE
getperm /dir/subdir/1/2/3/4
mkdir /dir/subdir/a/b/c/d
# Watch something, write to it, check watch has fired.
-write /test create contents
+write /test contents
1 watch /test token
-2 write /test create contents2
+2 write /test contents2
expect 1:/test:token
1 waitwatch
1 ackwatch token
# ignore watches while doing commands, should work.
watch /dir token
-1 write /dir/test create contents
+1 write /dir/test contents
expect contents
read /dir/test
expect /dir/test:token
1 watch /dir token1
3 watch /dir token3
2 watch /dir token2
-write /dir/test create contents
+write /dir/test contents
expect 3:/dir/test:token3
3 waitwatch
3 ackwatch token3
# If one dies (without acking), the other should still get ack.
1 watch /dir token1
2 watch /dir token2
-write /dir/test create contents
+write /dir/test contents
expect 2:/dir/test:token2
2 waitwatch
2 close
# If one dies (without reading at all), the other should still get ack.
1 watch /dir token1
2 watch /dir token2
-write /dir/test create contents
+write /dir/test contents
2 close
expect 1:/dir/test:token1
1 waitwatch
1 watch /dir token1
1 unwatch /dir token1
1 watch /dir token2
-2 write /dir/test2 create contents
+2 write /dir/test2 contents
expect 1:/dir/test2:token2
1 waitwatch
1 unwatch /dir token2
# unwatch while watch pending. Other watcher still gets the event.
1 watch /dir token1
2 watch /dir token2
-write /dir/test create contents
+write /dir/test contents
2 unwatch /dir token2
expect 1:/dir/test:token1
1 waitwatch
# unwatch while watch pending. Should clear this so we get next event.
1 watch /dir token1
-write /dir/test create contents
+write /dir/test contents
1 unwatch /dir token1
1 watch /dir/test token2
-write /dir/test none contents2
+write /dir/test contents2
expect 1:/dir/test:token2
1 waitwatch
1 ackwatch token2
# check we only get notified once.
1 watch /test token
-2 write /test create contents2
+2 write /test contents2
expect 1:/test:token
1 waitwatch
1 ackwatch token
# watches are queued in order.
1 watch / token
-2 write /test1 create contents
-2 write /test2 create contents
-2 write /test3 create contents
+2 write /test1 contents
+2 write /test2 contents
+2 write /test3 contents
expect 1:/test1:token
1 waitwatch
1 ackwatch token
# Creation of subpaths should be covered correctly.
1 watch / token
-2 write /test/subnode create contents2
-2 write /test/subnode/subnode create contents2
+2 write /test/subnode contents2
+2 write /test/subnode/subnode contents2
expect 1:/test/subnode:token
1 waitwatch
1 ackwatch token
# Watch event must have happened before we registered interest.
1 watch / token
-2 write /test/subnode create contents2
+2 write /test/subnode contents2
1 watch / token2 0
expect 1:/test/subnode:token
1 waitwatch
# Watch should not double-send after we ack, even if we did something in between.
1 watch /test2 token
-2 write /test2/foo create contents2
+2 write /test2/foo contents2
expect 1:/test2/foo:token
1 waitwatch
expect 1:contents2
# Test transaction timeouts. Take a second each.
mkdir /test
-write /test/entry1 create contents
+write /test/entry1 contents
# Transactions can take as long as the want...
start /test
# Simple transaction: create a file inside transaction.
1 start /test
-1 write /test/entry1 create contents
+1 write /test/entry1 contents
2 dir /test
expect 1:entry1
1 dir /test
# Create a file and abort transaction.
1 start /test
-1 write /test/entry1 create contents
+1 write /test/entry1 contents
2 dir /test
expect 1:entry1
1 dir /test
1 abort
2 dir /test
-write /test/entry1 create contents
+write /test/entry1 contents
# Delete in transaction, commit
1 start /test
1 rm /test/entry1
2 dir /test
# Delete in transaction, abort.
-write /test/entry1 create contents
+write /test/entry1 contents
1 start /test
1 rm /test/entry1
expect 2:entry1
# Multiple events from single transaction don't trigger assert
1 watch /test token
2 start /test
-2 write /test/1 create contents
-2 write /test/2 create contents
+2 write /test/1 contents
+2 write /test/2 contents
2 commit
expect 1:/test/1:token
1 waitwatch
# Create a domain, write an entry.
expect handle is 1
introduce 1 100 7 /my/home
-1 write /entry1 create contents
+1 write /entry1 contents
expect entry1
expect tool
dir /
mkdir /home
expect handle is 1
introduce 1 100 7 /home
-1 write entry1 create contents
+1 write entry1 contents
expect contents
read /home/entry1
expect entry1
# Place a watch using a relative path: expect relative answer.
1 mkdir foo
1 watch foo token
-write /home/foo/bar create contents
+write /home/foo/bar contents
expect 1:foo/bar:token
1 waitwatch
1 ackwatch token
# Test watching from a domain.
# Watch something, write to it, check watch has fired.
-write /test create contents
+write /test contents
mkdir /dir
expect handle is 1
introduce 1 100 7 /my/home
1 watch /test token
-write /test create contents2
+write /test contents2
expect 1:/test:token
1 waitwatch
1 ackwatch token
expect handle is 1
introduce 1 100 7 /my/home
1 watch /dir token
-write /dir/test create contents
-1 write /dir/test2 create contents2
-1 write /dir/test3 create contents3
-1 write /dir/test4 create contents4
+write /dir/test contents
+1 write /dir/test2 contents2
+1 write /dir/test3 contents3
+1 write /dir/test4 contents4
expect 1:/dir/test:token
1 waitwatch
1 ackwatch token
1 watch /dir token1
1 unwatch /dir token1
1 watch /dir token2
-write /dir/test2 create contents
+write /dir/test2 contents
expect 1:/dir/test2:token2
1 waitwatch
1 unwatch /dir token2
expect handle is 1
introduce 1 100 7 /my/home
1 watch /dir token1
-write /dir/test2 create contents
+write /dir/test2 contents
1 unwatch /dir token1
release 1
1 close
# Test that read only connection can't alter store.
-write /test create contents
+write /test contents
readonly
expect test
# These don't work
expect write failed: Read-only file system
-write /test2 create contents
+write /test2 contents
expect write failed: Read-only file system
-write /test create contents
+write /test contents
expect setperm failed: Read-only file system
setperm /test 100 NONE
expect setperm failed: Read-only file system
# Check that watches work like normal.
watch / token
1 readwrite
-1 write /test create contents
+1 write /test contents
expect /test:token
waitwatch
ackwatch token
1 watch /test/1 token1
1 watch /test/2 token2
1 watch /test/3 token3
-2 write /test/2 create contents2
+2 write /test/2 contents2
expect 1:/test/2:token2
1 waitwatch
-3 write /test/1 create contents1
-4 write /test/3 create contents3
+3 write /test/1 contents1
+4 write /test/3 contents3
1 ackwatch token2
1 close
expect *Permission denied
read /dir/file
expect *Permission denied
-write /dir/file none value
-expect *Permission denied
-write /dir/file create value
-expect *Permission denied
-write /dir/file excl value
-expect write failed: Invalid argument
-write /dir/file crap value
+write /dir/file value
expect *Permission denied
mkdir /dir/file
expect *Permission denied
expect *Permission denied
setperm /dir/file 0 NONE
watch /dir/file token
-1 write /dir/file create contents
+1 write /dir/file contents
1 rm /dir/file
expect waitwatch failed: Connection timed out
waitwatch
# Now it exists
setid 0
-write /dir/file create contents
+write /dir/file contents
setid 1
expect *Permission denied
expect *Permission denied
read /dir/file
expect *Permission denied
-write /dir/file none value
-expect *Permission denied
-write /dir/file create value
-expect *Permission denied
-write /dir/file excl value
-expect write failed: Invalid argument
-write /dir/file crap value
+write /dir/file value
expect *Permission denied
mkdir /dir/file
expect *Permission denied
expect *Permission denied
setperm /dir/file 0 NONE
watch /dir/file token
-1 write /dir/file create contents
+1 write /dir/file contents
1 rm /dir/file
expect waitwatch failed: Connection timed out
waitwatch
# If we don't wait for an ack, we can crash daemon as it never expects to be
# sending out two replies on top of each other.
-noackwrite /1 create 1
-noackwrite /2 create 2
-noackwrite /3 create 3
-noackwrite /4 create 4
-noackwrite /5 create 5
+noackwrite /1 1
+noackwrite /2 2
+noackwrite /3 3
+noackwrite /4 4
+noackwrite /5 5
readack
readack
readack
expect handle is 1
introduce 1 100 7 /my/home
-1 noackwrite /1 create 1
-1 noackwrite /2 create 2
-1 noackwrite /3 create 3
-1 noackwrite /4 create 4
-1 noackwrite /5 create 5
+1 noackwrite /1 1
+1 noackwrite /2 2
+1 noackwrite /3 3
+1 noackwrite /4 4
+1 noackwrite /5 5
1 readack
1 readack
1 readack
watch /test token
1 start /test
# This will block on above
-noackwrite /test/entry create contents
-1 write /test/entry2 create contents
+noackwrite /test/entry contents
+1 write /test/entry2 contents
1 commit
readack
expect /test/entry2:token
return lstat(node_dir(conn->transaction, node), &st) == 0;
}
-/* path, flags, data... */
+/* path, data... */
static void do_write(struct connection *conn, struct buffered_data *in)
{
unsigned int offset, datalen;
- char *vec[2];
+ char *vec[1] = { NULL }; /* gcc4 + -W + -Werror fucks code. */
char *node, *tmppath;
- enum xs_perm_type mode;
- struct stat st;
/* Extra "strings" can be created by binary data. */
if (get_strings(in, vec, ARRAY_SIZE(vec)) < ARRAY_SIZE(vec)) {
if (transaction_block(conn, node))
return;
- offset = strlen(vec[0]) + strlen(vec[1]) + 2;
+ offset = strlen(vec[0]) + 1;
datalen = in->used - offset;
- if (streq(vec[1], XS_WRITE_NONE))
- mode = XS_PERM_WRITE;
- else if (streq(vec[1], XS_WRITE_CREATE))
- mode = XS_PERM_WRITE|XS_PERM_ENOENT_OK;
- else if (streq(vec[1], XS_WRITE_CREATE_EXCL))
- mode = XS_PERM_WRITE|XS_PERM_ENOENT_OK;
- else {
- send_error(conn, EINVAL);
- return;
- }
-
- if (!check_node_perms(conn, node, mode)) {
+ if (!check_node_perms(conn, node, XS_PERM_WRITE|XS_PERM_ENOENT_OK)) {
send_error(conn, errno);
return;
}
- if (lstat(node_dir(conn->transaction, node), &st) != 0) {
+ if (!node_exists(conn, node)) {
char *dir;
/* Does not exist... */
return;
}
- /* Not going to create it? */
- if (streq(vec[1], XS_WRITE_NONE)) {
- send_error(conn, ENOENT);
- return;
- }
-
dir = tempdir(conn, node, in->buffer + offset, datalen);
if (!dir || !commit_dir(dir)) {
send_error(conn, errno);
} else {
/* Exists... */
- if (streq(vec[1], XS_WRITE_CREATE_EXCL)) {
- send_error(conn, EEXIST);
- return;
- }
-
tmppath = tempfile(node_datafile(conn->transaction, node),
in->buffer + offset, datalen);
if (!tmppath) {
}
/* Write the value of a single file.
- * Returns false on failure. createflags can be 0, O_CREAT, or O_CREAT|O_EXCL.
+ * Returns false on failure.
*/
bool xs_write(struct xs_handle *h, const char *path,
- const void *data, unsigned int len, int createflags)
-{
- const char *flags;
- struct iovec iovec[3];
-
- /* Format: Flags (as string), path, data. */
- if (createflags == 0)
- flags = XS_WRITE_NONE;
- else if (createflags == O_CREAT)
- flags = XS_WRITE_CREATE;
- else if (createflags == (O_CREAT|O_EXCL))
- flags = XS_WRITE_CREATE_EXCL;
- else {
- errno = EINVAL;
- return false;
- }
+ const void *data, unsigned int len)
+{
+ struct iovec iovec[2];
iovec[0].iov_base = (void *)path;
iovec[0].iov_len = strlen(path) + 1;
- iovec[1].iov_base = (void *)flags;
- iovec[1].iov_len = strlen(flags) + 1;
- iovec[2].iov_base = (void *)data;
- iovec[2].iov_len = len;
+ iovec[1].iov_base = (void *)data;
+ iovec[1].iov_len = len;
return xs_bool(xs_talkv(h, XS_WRITE, iovec, ARRAY_SIZE(iovec), NULL));
}
void *xs_read(struct xs_handle *h, const char *path, unsigned int *len);
/* Write the value of a single file.
- * Returns false on failure. createflags can be 0, O_CREAT, or O_CREAT|O_EXCL.
+ * Returns false on failure.
*/
bool xs_write(struct xs_handle *h, const char *path, const void *data,
- unsigned int len, int createflags);
+ unsigned int len);
/* Create a new directory.
* Returns false on failure, or success if it already exists.
free(xs_read(h, name, &num));
break;
case 2: {
- int flags = random_flags(&state);
char *contents = talloc_asprintf(NULL, "%i",
get_randomness(&state));
unsigned int len = get_randomness(&state)%(strlen(contents)+1);
if (verbose)
- printf("WRITE %s %s %.*s\n", name,
- flags == O_CREAT ? "O_CREAT"
- : flags == (O_CREAT|O_EXCL) ? "O_CREAT|O_EXCL"
- : flags == 0 ? "0" : "CRAPFLAGS",
- len, contents);
- xs_write(h, name, contents, len, flags);
+ printf("WRITE %s %.*s\n", name, len, contents);
+ xs_write(h, name, contents, len);
break;
}
case 3:
void *(*read)(void *h, const char *path, unsigned int *len);
bool (*write)(void *h, const char *path, const void *data,
- unsigned int len, int createflags);
+ unsigned int len);
bool (*mkdir)(void *h, const char *path);
static bool file_write(struct file_ops_info *info,
const char *path, const void *data,
- unsigned int len, int createflags)
+ unsigned int len)
{
char *filename = filename_to_data(path_to_name(info, path));
int fd;
- /* Kernel isn't strict, but library is. */
- if (createflags & ~(O_CREAT|O_EXCL)) {
- errno = EINVAL;
- return false;
- }
-
if (!write_ok(info, path))
return false;
- /* We regard it as existing if dir exists. */
- if (strends(filename, ".DATA")) {
- if (!createflags)
- createflags = O_CREAT;
- if (createflags & O_EXCL) {
- errno = EEXIST;
- return false;
- }
- }
-
- if (createflags & O_CREAT)
- make_dirs(parent_filename(filename));
-
- fd = open(filename, createflags|O_TRUNC|O_WRONLY, 0600);
- if (fd < 0) {
- /* FIXME: Another hack. */
- if (!(createflags & O_CREAT) && errno == EISDIR)
- errno = EEXIST;
+ make_dirs(parent_filename(filename));
+ fd = open(filename, O_CREAT|O_TRUNC|O_WRONLY, 0600);
+ if (fd < 0)
return false;
- }
if (write(fd, data, len) != (int)len)
barf_perror("Bad write to %s", filename);
return ret;
}
-static int random_flags(int *state)
-{
- switch (get_randomness(state) % 4) {
- case 0:
- return 0;
- case 1:
- return O_CREAT;
- case 2:
- return O_CREAT|O_EXCL;
- default:
- return get_randomness(state);
- }
-}
-
/* Do the next operation, return the results. */
static char *do_next_op(struct ops *ops, void *h, int state, bool verbose)
{
ret = linearize_read(ops->read(h, name, &num), &num);
break;
case 2: {
- int flags = random_flags(&state);
char *contents = talloc_asprintf(NULL, "%i",
get_randomness(&state));
unsigned int len = get_randomness(&state)%(strlen(contents)+1);
if (verbose)
- printf("WRITE %s %s %.*s\n", name,
- flags == O_CREAT ? "O_CREAT"
- : flags == (O_CREAT|O_EXCL) ? "O_CREAT|O_EXCL"
- : flags == 0 ? "0" : "CRAPFLAGS",
- len, contents);
- ret = bool_to_errstring(ops->write(h, name, contents, len,
- flags));
+ printf("WRITE %s %.*s\n", name, len, contents);
+ ret = bool_to_errstring(ops->write(h, name, contents, len));
talloc_steal(ret, contents);
break;
}
barf_perror("%i: can't read %s iter %i",
childnum, file, i);
sprintf(tmp, "%i", atoi(contents) + 1);
- if (!xs_write(h, file, tmp, strlen(tmp)+1, 0))
+ if (!xs_write(h, file, tmp, strlen(tmp)+1))
barf_perror("%i: can't write %s iter %i",
childnum, file, i);
if (togo == 0) {
sprintf(filename, "%s/count", base);
- if (!xs_write(h, filename, "0", 2, O_EXCL|O_CREAT))
+ if (!xs_write(h, filename, "0", 1))
barf_perror("Writing to %s", filename);
return;
}
"Reads commands from stdin, one per line:"
" dir <path>\n"
" read <path>\n"
- " write <path> <flags> <value>...\n"
+ " write <path> <value>...\n"
" setid <id>\n"
" mkdir <path>\n"
" rm <path>\n"
" notimeout\n"
" readonly\n"
" readwrite\n"
- " noackwrite <path> <flags> <value>...\n"
+ " noackwrite <path> <value>...\n"
" readack\n"
" dump\n");
}
output("%.*s\n", len, value);
}
-static void do_write(unsigned int handle, char *path, char *flags, char *data)
+static void do_write(unsigned int handle, char *path, char *data)
{
- int f;
-
- if (streq(flags, "none"))
- f = 0;
- else if (streq(flags, "create"))
- f = O_CREAT;
- else if (streq(flags, "excl"))
- f = O_CREAT | O_EXCL;
- else if (streq(flags, "crap"))
- f = 100;
- else
- barf("write flags 'none', 'create' or 'excl' only");
-
- if (!xs_write(handles[handle], path, data, strlen(data), f))
+ if (!xs_write(handles[handle], path, data, strlen(data)))
failed(handle);
}
static void do_noackwrite(unsigned int handle,
- char *path, const char *flags, char *data)
+ char *path, char *data)
{
struct xsd_sockmsg msg;
- /* Format: Flags (as string), path, data. */
- if (streq(flags, "none"))
- flags = XS_WRITE_NONE;
- else if (streq(flags, "create"))
- flags = XS_WRITE_CREATE;
- else if (streq(flags, "excl"))
- flags = XS_WRITE_CREATE_EXCL;
- else
- barf("noackwrite flags 'none', 'create' or 'excl' only");
-
- msg.len = strlen(path) + 1 + strlen(flags) + 1 + strlen(data);
+ msg.len = strlen(path) + 1 + strlen(data);
msg.type = XS_WRITE;
if (!write_all_choice(handles[handle]->fd, &msg, sizeof(msg)))
failed(handle);
if (!write_all_choice(handles[handle]->fd, path, strlen(path) + 1))
failed(handle);
- if (!write_all_choice(handles[handle]->fd, flags, strlen(flags) + 1))
- failed(handle);
if (!write_all_choice(handles[handle]->fd, data, strlen(data)))
failed(handle);
/* Do not wait for ack. */
else if (streq(command, "read"))
do_read(handle, arg(line, 1));
else if (streq(command, "write"))
- do_write(handle,
- arg(line, 1), arg(line, 2), arg(line, 3));
+ do_write(handle, arg(line, 1), arg(line, 2));
else if (streq(command, "setid"))
do_setid(handle, arg(line, 1));
else if (streq(command, "mkdir"))
xs_daemon_close(handles[handle]);
handles[handle] = NULL;
} else if (streq(command, "noackwrite"))
- do_noackwrite(handle, arg(line,1), arg(line,2), arg(line,3));
+ do_noackwrite(handle, arg(line,1), arg(line,2));
else if (streq(command, "readack"))
do_readack(handle);
else